#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 500020;
struct offlineNode{
	ll q,x;
}offline[MAXN];
ll b[MAXN];
ll n;
struct Node{
	ll l,r,val;
}T[MAXN<<2];
#define lc(p) p<<1
#define rc(p) p<<1|1
inline void push_up(ll root){
	T[root].val=T[lc(root)].val+T[rc(root)].val;
}
void build(ll root,ll l,ll r){
	T[root].l=l,T[root].r=r,T[root].val=0;
	if(l==r){
		return;
	}
	ll mid=(l+r)>>1;
	build(lc(root),l,mid);
	build(rc(root),mid+1,r);
}
void updata(ll root,ll x,ll p){
	if(T[root].l==T[root].r){
		T[root].val+=p;
		return;
	}
	ll mid=(T[root].l+T[root].r)>>1;
	if(x<=mid)updata(lc(root),x,p);
	else updata(rc(root),x,p);
	push_up(root);
}
ll query(ll root,ll l,ll r){
	if(T[root].l>=l&&T[root].r<=r)return T[root].val;
	ll mid=(T[root].l+T[root].r)>>1;
	ll ans=0;
	if(l<=mid)ans+=query(lc(root),l,r);
	if(r>mid)ans+=query(rc(root),l,r);
	return ans;
}
ll requery(ll root,ll len){
	if(T[root].l==T[root].r)return T[root].l;
	if(len<=T[lc(root)].val)return requery(lc(root),len);
	else return requery(rc(root),len-T[lc(root)].val);
}
ll cnt=0,act,c[MAXN];
int main(void){
	scanf("%lld",&n);
	build(1,1,5*1e5+10);
	for(ll i=1;i<=n;i++){
		scanf("%lld",&b[i]);
		c[i]=b[i];
	}
	act=n;
	sort(b+1,b+n+1);
	n=unique(b+1,b+n+1)-(b+1);
	for(ll i=1;i<=act;i++){
		ll x=lower_bound(b+1,b+n+1,c[i])-b;
		updata(1,x,1);
		cnt+=(i-query(1,1,x));
	}
	cout<<cnt;
	return 0;
}
